/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ejercicio.practica7;

import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;

/**
 *
 * @author manolo
 */
public class clienteMultiple {

    Socket enchufe;

    public clienteMultiple() {
    }

    public clienteMultiple(Socket s) {
        enchufe = s;
    }

    public static void main(String[] args) {
        int i = (int) (Math.random() * 10);
        int puerto = 2001;
        for (int j = 0; j < 10; j++) {
            try {
                System.out.println("Realizando conexion...");
                Socket cable = new Socket("localhost", puerto);
                System.out.println("Realizada conexion a " + cable);
                PrintWriter salida = new PrintWriter(new BufferedWriter(new OutputStreamWriter(cable.getOutputStream())));
                salida.println(i);
                salida.flush();
                System.out.println("Cerrando conexion...");
                cable.close();
            } catch (Exception e) {
                System.out.println("Error en sockets...");
            }
        }
    }
}
